//
//  WBNavigationController.swift
//  WeiBo
//
//  Created by liushaohua on 16/10/22.
//  Copyright © 2016年 liushaohua. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        
        // 如果自定义返回按钮则 拖动会失效
        // 设置代理  就可以返回了
        interactivePopGestureRecognizer?.delegate = self
        
    }
    
    //MARK:重写父类的push方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        
        var title:String?
        //
        if childViewControllers.count > 0 {
            
            title = "返回"
        
        if childViewControllers.count == 1 {
            title = childViewControllers.first?.title
            
        }
        viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(setHighlightedImg:"navigationbar_back_withtext", title: title, target: self, action: #selector(popVC))
        
        }
        super.pushViewController(viewController, animated: animated)
    }
  // 设置私有方法
   @objc private func popVC(){
    
       popViewController(animated: true)
    }
    //MARK: 在首页是不能在拖动
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        return childViewControllers.count != 1
    }
    

}
